
// check-node-version.js

import semver from "semver";
// 设置支持的node版本
const desiredVersions = [
    '^18.18.0',
    '^20.9.0',
    '>=21.1.0'
];

const currentVersion = process.version;

let isValidVersion = false;

for (const versionRange of desiredVersions) {
    if (semver.satisfies(currentVersion, versionRange)) {
        isValidVersion = true;
        break;
    }
}

if (!isValidVersion) {
    console.error(`Unsupported Node.js version: ${currentVersion}. 受eslint的影响，要求node版本 versions: ${desiredVersions.join(', ')}`);
    process.exit(1); // 退出并返回一个非零状态码，表示错误
} else if (!/pnpm/.test(process.env.npm_execpath || '')) {
    console.warn(
        `\u001b[33m禁止使用除pnpm以外的包管理器安装依赖.\u001b[39m\n`,
    )
    process.exit(1)
}
console.log(`Node.js version ${currentVersion} is supported.`);